{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "40ba5be7-5f66-42a7-9a55-2a8661f03133",
   "metadata": {},
   "outputs": [],
   "source": [
    "class C:\n",
    "    attr:int"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "94c0fccc-fbc3-4722-9fb0-ad54804fbc30",
   "metadata": {},
   "outputs": [],
   "source": [
    "class D(C):\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "02c3afe6-3254-4254-9700-fffdf13d252d",
   "metadata": {},
   "outputs": [],
   "source": [
    "c=C()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b3695d5d-f97e-44de-bb52-1a1c83db2461",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "mappingproxy({'__module__': '__main__',\n",
       "              '__annotations__': {'attr': int},\n",
       "              '__dict__': <attribute '__dict__' of 'C' objects>,\n",
       "              '__weakref__': <attribute '__weakref__' of 'C' objects>,\n",
       "              '__doc__': None})"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "C.__dict__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f91e174d-466a-4ced-a7f2-ca77909b1f89",
   "metadata": {},
   "outputs": [],
   "source": [
    "instance_c = C\n",
    "instance_d = D"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "c4ab8a7e-1d36-4e10-860e-171e430142e6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "mappingproxy({'__module__': '__main__',\n",
       "              '__annotations__': {'attr': int},\n",
       "              '__dict__': <attribute '__dict__' of 'C' objects>,\n",
       "              '__weakref__': <attribute '__weakref__' of 'C' objects>,\n",
       "              '__doc__': None})"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "instance_c.__dict__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7961e8b6-5336-44fa-81ca-2d3a18c4771f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "mappingproxy({'__module__': '__main__', '__doc__': None})"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "instance_d.__dict__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "bdf06e4a-5888-40d9-85b0-2dbd46656c2c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dynamic attr_test\n",
      "Dynamic attr_test\n"
     ]
    }
   ],
   "source": [
    "class C:\n",
    "    def __init__(self, name):\n",
    "        self.name = name\n",
    "    def __getattr__(self, name):\n",
    "        if name.startswith(\"attr_\"):\n",
    "            setattr(self, name, f\"Dynamic {name}\")\n",
    "            return getattr(self, name)\n",
    "        else:\n",
    "            raise AttributeError(f\"'{type(self).__name__}' object has no attribute '{name}'\")\n",
    "c = C(\"tom\")\n",
    "print(c.attr_test)\n",
    "print(c.attr_test)\n",
    "#print(c.some_other_attr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "3c80dda8-183c-44e7-9128-e3d1aa268d20",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'name': 'tom', 'attr_test': 'Dynamic attr_test'}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vars(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "655117de-0dc7-468d-be8e-a5293269d629",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hasattr(c,\"name\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "f26d67ce-1ad7-44f1-85c5-33e4463dfefd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hasattr(c, \"attr_test\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "6ec2325a-6485-467a-b90d-a6f8e7733d21",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<__main__.C at 0x28bfc491c50>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "6240008a-840f-4aa5-87ae-849f0a8b0371",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2800256359504"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "id(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "de341868-a9d5-4bd2-be15-cfe1300cf34f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "175016022469"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hash(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "58fd3d75-6bbd-4cf9-bf5a-e9f45dc8270a",
   "metadata": {},
   "outputs": [],
   "source": [
    "#locals()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "60739161-4f34-4f8c-9264-bb72373df67e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d8fe7965-dab5-4715-a3fb-2e309ae0b695",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Py(Python note)",
   "language": "python",
   "name": "pynote"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
